'''
Created on 02/08/2010

@author: eh01
'''
from datastore.resource import Resource
from datastore.spaces import Spaces
from datastore.uri import Uri
from runtime.nodelogger import NodeLogger
from spear.a2pspear_service import A2PSpearService
import os
import unittest
import logging
import datetime

class A2PSPEARServiceTest(unittest.TestCase):

    ACTIONS_FILE_DIR = '../../src/spear/actions'
    ACTIONS_FILE_DIR_WHEN_RUNNING_FROM_ANT = '../src/spear/actions'
    ACTIONS_FILE_PATH = '../../src/spear/actions/%s'
    ACTIONS_FILE_PATH_WHEN_RUNNING_FROM_ANT = '../src/spear/actions/%s'
    CONFIGURATION_FILE_PATH = '../../src/spear/a2pspear_service.xml'
    CONFIGURATION_FILE_PATH_WHEN_RUNNING_FROM_ANT = '../src/spear/a2pspear_service.xml'

    def setUp(self):
        self.request_rss = []
        self.instructions_rss = {}
        if os.path.isdir(A2PSPEARServiceTest.ACTIONS_FILE_DIR):
            actions_file_dir = A2PSPEARServiceTest.ACTIONS_FILE_DIR
            actions_file_path = A2PSPEARServiceTest.ACTIONS_FILE_PATH
        else:
            actions_file_dir = A2PSPEARServiceTest.ACTIONS_FILE_DIR_WHEN_RUNNING_FROM_ANT
            actions_file_path = A2PSPEARServiceTest.ACTIONS_FILE_PATH_WHEN_RUNNING_FROM_ANT
        for file_name in os.listdir(actions_file_dir):
            if file_name.endswith('.xml'):
                rs = Resource(type="temp")
                rs.load_from_file(actions_file_path % file_name)
                if rs.get_type() == Uri("spear:type/request"):
                    self.request_rss.append(rs)
                else:
                    self.instructions_rss[rs.get_metadata(Uri("spear:instruction/uri"))] = rs
                
    def tearDown(self):
        self.request_rss = None
        self.instructions_rss = None

    def get_spear_action(self, file_name):
        action_rs = Resource(type="temp")
        if os.path.isfile(A2PSPEARServiceTest.ACTIONS_FILE_PATH % file_name):
            action_file_path = A2PSPEARServiceTest.ACTIONS_FILE_PATH
        else:
            action_file_path = A2PSPEARServiceTest.ACTIONS_FILE_PATH_WHEN_RUNNING_FROM_ANT
        action_rs.load_from_file(action_file_path % file_name)
        return action_rs
    
    def get_a2pspear_service_configuration(self):
        config_rs = Resource(type="temp")
        if os.path.isfile(A2PSPEARServiceTest.CONFIGURATION_FILE_PATH):
            action_file_path = A2PSPEARServiceTest.CONFIGURATION_FILE_PATH
        else:
            action_file_path = A2PSPEARServiceTest.CONFIGURATION_FILE_PATH_WHEN_RUNNING_FROM_ANT
        config_rs.load_from_file(action_file_path)
        return config_rs

    def get_requests_resources_from_datastore(self):
        return self.request_rss
    
    def get_instruction_resource_from_datastore(self, instruction_uri):
        if instruction_uri in self.instructions_rss:
            return self.instructions_rss[instruction_uri]
        else:
            return None
            
    def test_do_process_request_login(self):
        NodeLogger.logger_names['eplanning.spear.a2pspear_service'] = logging.DEBUG
        NodeLogger.logger_names['eplanning.spear.a2pspear_service.A2PSpearService'] = logging.DEBUG
        NodeLogger.setStreamHandler()        
        NodeLogger.load()
        spaces = Spaces()
        service_uri = Uri('dummy')
        ds = None
        config_rs = self.get_a2pspear_service_configuration()
        A2PSpearService.get_requests_resources_from_datastore = self.get_requests_resources_from_datastore
        A2PSpearService.get_instruction_resource_from_datastore = self.get_instruction_resource_from_datastore
        a2pspear_service = A2PSpearService(spaces, ds, service_uri)
        a2pspear_service.statics = config_rs.services["eplanning/spear/a2pspear_service"].options.statics
        request_rs = spaces.get(Uri("spear:request/login"))
        output_rs = a2pspear_service.do_process_request(request_rs, spaces)
        self.assertEqual(True, output_rs.success)
        self.assertEqual('85:LOCAL_ADMINISTRATOR', output_rs.user_role_administrator)
        self.assertEqual('85:RESPONSIBLE_AUTHORITY', output_rs.user_role_council)
        
    def test_do_process_request_users(self):
        NodeLogger.logger_names['eplanning.spear.a2pspear_service'] = logging.DEBUG
        NodeLogger.logger_names['eplanning.spear.a2pspear_service.A2PSpearService'] = logging.DEBUG
        NodeLogger.setStreamHandler()        
        NodeLogger.load()
        spaces = Spaces()
        service_uri = Uri('dummy')
        ds = None
        config_rs = self.get_a2pspear_service_configuration()
        A2PSpearService.get_requests_resources_from_datastore = self.get_requests_resources_from_datastore
        A2PSpearService.get_instruction_resource_from_datastore = self.get_instruction_resource_from_datastore
        a2pspear_service = A2PSpearService(spaces, ds, service_uri)
        a2pspear_service.statics = config_rs.services["eplanning/spear/a2pspear_service"].options.statics
        request_rs = spaces.get(Uri("spear:request/login"))
        output_rs = a2pspear_service.do_process_request(request_rs, spaces)
        self.assertEqual(True, output_rs.success)
        request_rs = spaces.get(Uri("spear:request/users"))
        args_dict = {}
        args_dict["user_role_council"] = "85:RESPONSIBLE_AUTHORITY"
        args_dict["user_role_administrator"] = "85:LOCAL_ADMINISTRATOR"
        request_rs.arguments_dict = args_dict
        output_rs = a2pspear_service.do_process_request(request_rs, spaces)
        self.assertEqual(True, output_rs.success)
        self.assertTrue(output_rs.sid102a_dict_list)
        for dict in output_rs.sid102a_dict_list:
            self.assertTrue('sid102a_first_name' in dict)
            self.assertTrue('sid102a_authentication_level' in dict)
            self.assertTrue('sid102a_user_status' in dict)
            self.assertTrue('sid102a_last_name' in dict)
            self.assertTrue('sid102a_sites' in dict)
            self.assertTrue('sid102a_user_id' in dict)
            self.assertTrue('sid102a_user_roles' in dict)
        
    def test_do_process_request_ras(self):
        NodeLogger.logger_names['eplanning.spear.a2pspear_service'] = logging.DEBUG
        NodeLogger.logger_names['eplanning.spear.a2pspear_service.A2PSpearService'] = logging.DEBUG
        NodeLogger.setStreamHandler()        
        NodeLogger.load()
        spaces = Spaces()
        service_uri = Uri('dummy')
        ds = None
        config_rs = self.get_a2pspear_service_configuration()
        A2PSpearService.get_requests_resources_from_datastore = self.get_requests_resources_from_datastore
        A2PSpearService.get_instruction_resource_from_datastore = self.get_instruction_resource_from_datastore
        a2pspear_service = A2PSpearService(spaces, ds, service_uri)
        a2pspear_service.statics = config_rs.services["eplanning/spear/a2pspear_service"].options.statics
        request_rs = spaces.get(Uri("spear:request/login"))
        output_rs = a2pspear_service.do_process_request(request_rs, spaces)
        self.assertEqual(True, output_rs.success)
        request_rs = spaces.get(Uri("spear:request/ras"))
        args_dict = {}
        args_dict["user_role_council"] = "85:RESPONSIBLE_AUTHORITY"
        args_dict["user_role_administrator"] = "85:LOCAL_ADMINISTRATOR"
        request_rs.arguments_dict = args_dict
        output_rs = a2pspear_service.do_process_request(request_rs, spaces)
        self.assertEqual(True, output_rs.success)                

    def test_do_process_request_current_application_list(self):
        NodeLogger.logger_names['eplanning.spear.a2pspear_service'] = logging.DEBUG
        NodeLogger.logger_names['eplanning.spear.a2pspear_service.A2PSpearService'] = logging.DEBUG
        NodeLogger.setStreamHandler()        
        NodeLogger.load()
        spaces = Spaces()
        service_uri = Uri('dummy')
        ds = None
        config_rs = self.get_a2pspear_service_configuration()
        A2PSpearService.get_requests_resources_from_datastore = self.get_requests_resources_from_datastore
        A2PSpearService.get_instruction_resource_from_datastore = self.get_instruction_resource_from_datastore
        a2pspear_service = A2PSpearService(spaces, ds, service_uri)
        a2pspear_service.statics = config_rs.services["eplanning/spear/a2pspear_service"].options.statics
        request_rs = spaces.get(Uri("spear:request/login"))
        output_rs = a2pspear_service.do_process_request(request_rs, spaces)
        self.assertEqual(True, output_rs.success)
        request_rs = spaces.get(Uri("spear:request/currentapplicationlist"))
        args_dict = {}
        args_dict["user_role_council"] = "85:RESPONSIBLE_AUTHORITY"
        request_rs.arguments_dict = args_dict
        output_rs = a2pspear_service.do_process_request(request_rs, spaces)
        self.assertEqual(True, output_rs.success)
        self.assertTrue(output_rs.sid002b_dict_list)
        for dict in output_rs.sid002b_dict_list:
            self.assertTrue('sid002b_date_lodged_with_responsible_authority' in dict)
            self.assertTrue('sid002b_action' in dict)
            self.assertTrue('sid002b_advertised_indicator' in dict)
            self.assertTrue('sid002b_air_indicator' in dict)
            self.assertTrue('sid002b_council_ref' in dict)
            self.assertTrue('sid002b_app_id' in dict)
            self.assertTrue('sid002b_status' in dict)
            self.assertTrue('sid002b_objected_indicator' in dict)
            self.assertTrue('sid002b_applicant_contact' in dict)
            self.assertTrue('sid002b_plan_number' in dict)
            self.assertTrue('sid002b_type' in dict)
            self.assertTrue('sid002b_appealed_indicator' in dict)
            self.assertTrue('sid002b_spear_ref' in dict)
            self.assertTrue('sid002b_council_hosted_indicator' in dict)
            self.assertTrue('sid002b_cc_version' in dict)
            self.assertTrue('sid002b_property_details' in dict)
            
    def test_do_process_request_application_details(self):
        NodeLogger.logger_names['eplanning.spear.a2pspear_service'] = logging.DEBUG
        NodeLogger.logger_names['eplanning.spear.a2pspear_service.A2PSpearService'] = logging.DEBUG
        NodeLogger.setStreamHandler()        
        NodeLogger.load()
        spaces = Spaces()
        service_uri = Uri('dummy')
        ds = None
        config_rs = self.get_a2pspear_service_configuration()
        A2PSpearService.get_requests_resources_from_datastore = self.get_requests_resources_from_datastore
        A2PSpearService.get_instruction_resource_from_datastore = self.get_instruction_resource_from_datastore
        a2pspear_service = A2PSpearService(spaces, ds, service_uri)
        a2pspear_service.statics = config_rs.services["eplanning/spear/a2pspear_service"].options.statics
        request_rs = spaces.get(Uri("spear:request/login"))
        output_rs = a2pspear_service.do_process_request(request_rs, spaces)
        self.assertEqual(True, output_rs.success)
        request_rs = spaces.get(Uri("spear:request/applicationdetails"))
        args_dict = {}
        args_dict["spearReferenceNumber"] = 'S008090V'
        args_dict["user_role_council"] = "85:RESPONSIBLE_AUTHORITY"
        request_rs.arguments_dict = args_dict
        output_rs = a2pspear_service.do_process_request(request_rs, spaces)
        self.assertEqual(True, output_rs.success)
        self.assertTrue(output_rs.sid004_dict)
        self.assertTrue('sid004_current_actors_mandatory_action_list' in output_rs.sid004_dict)
        self.assertTrue('sid004_optional_action_list' in output_rs.sid004_dict)
        self.assertTrue('sid004_attachment_dict_list' in output_rs.sid004_dict) 
        for dict in output_rs.sid004_dict['sid004_attachment_dict_list']:
            self.assertTrue('sid004_owner__derived' in dict)
            self.assertTrue('sid004_doctype' in dict)
            self.assertTrue('sid004_complementary_doctype_link_dict_list' in dict)
            for dict2 in dict['sid004_complementary_doctype_link_dict_list']:
                self.assertTrue('title' in dict2)
                self.assertTrue('url' in dict2)
            self.assertTrue('sid004_objection_withdrawn' in dict)
            self.assertTrue('sid004_date' in dict)
            self.assertTrue('sid004_completed_action_phrase' in dict)
            self.assertTrue('document_url' in dict)
            self.assertTrue('sid004_doc_title__derived' in dict)
            self.assertTrue('sid004_owner_type__derived' in dict)

    def test_do_process_request_application_document(self):
        NodeLogger.logger_names['eplanning.spear.a2pspear_service'] = logging.DEBUG
        NodeLogger.logger_names['eplanning.spear.a2pspear_service.A2PSpearService'] = logging.DEBUG
        NodeLogger.setStreamHandler()        
        NodeLogger.load()
        spaces = Spaces()
        service_uri = Uri('dummy')
        ds = None
        config_rs = self.get_a2pspear_service_configuration()
        A2PSpearService.get_requests_resources_from_datastore = self.get_requests_resources_from_datastore
        A2PSpearService.get_instruction_resource_from_datastore = self.get_instruction_resource_from_datastore
        a2pspear_service = A2PSpearService(spaces, ds, service_uri)
        a2pspear_service.statics = config_rs.services["eplanning/spear/a2pspear_service"].options.statics
        request_rs = spaces.get(Uri("spear:request/login"))
        output_rs = a2pspear_service.do_process_request(request_rs, spaces)
        self.assertEqual(True, output_rs.success)
        request_rs = spaces.get(Uri("spear:request/applicationdetails"))
        args_dict = {}
        args_dict["spearReferenceNumber"] = 'S007533P'
        args_dict["user_role_council"] = "85:RESPONSIBLE_AUTHORITY"
        request_rs.arguments_dict = args_dict
        output_rs = a2pspear_service.do_process_request(request_rs, spaces)
        self.assertEqual(True, output_rs.success)
        request_rs = spaces.get(Uri("spear:request/applicationdocument"))
        args_dict = {}
        args_dict["user_role_council"] = "85:RESPONSIBLE_AUTHORITY"
        args_dict["documentUrlPath"] = "/spear/document/View.do"
        args_dict["documentUrlQuery"] = "documentId=104353&spearAppToken=7605&dmdInternalID=107786&caller=details"
        request_rs.arguments_dict = args_dict
        output_rs = a2pspear_service.do_process_request(request_rs, spaces)
        self.assertEqual(True, output_rs.success)
        self.assertTrue(output_rs.sid005a_dict)
        self.assertTrue('document_url' in output_rs.sid005a_dict)
        self.assertTrue('sid005a_current_document_prefix' in output_rs.sid005a_dict)
        self.assertTrue('sid005a_current_document_doctype' in output_rs.sid005a_dict)
        self.assertTrue('sid005a_doctype' in output_rs.sid005a_dict)
        self.assertTrue('sid005a_current_document_version_number' in output_rs.sid005a_dict)
        self.assertTrue('sid005a_current_document_authenticated_by' in output_rs.sid005a_dict)
        self.assertTrue('sid005a_current_document_submitted_date' in output_rs.sid005a_dict) 
        
    def test_do_process_request_application_document_applicationforplanningpermit(self):
        NodeLogger.logger_names['eplanning.spear.a2pspear_service'] = logging.DEBUG
        NodeLogger.logger_names['eplanning.spear.a2pspear_service.A2PSpearService'] = logging.DEBUG
        NodeLogger.setStreamHandler()        
        NodeLogger.load()
        spaces = Spaces()
        service_uri = Uri('dummy')
        ds = None
        config_rs = self.get_a2pspear_service_configuration()
        A2PSpearService.get_requests_resources_from_datastore = self.get_requests_resources_from_datastore
        A2PSpearService.get_instruction_resource_from_datastore = self.get_instruction_resource_from_datastore
        a2pspear_service = A2PSpearService(spaces, ds, service_uri)
        a2pspear_service.statics = config_rs.services["eplanning/spear/a2pspear_service"].options.statics
        request_rs = spaces.get(Uri("spear:request/login"))
        output_rs = a2pspear_service.do_process_request(request_rs, spaces)
        self.assertEqual(True, output_rs.success)
        request_rs = spaces.get(Uri("spear:request/applicationdocument-applicationforplanningpermit"))
        args_dict = {}
        args_dict["user_role_council"] = "85:RESPONSIBLE_AUTHORITY"
        args_dict["documentUrlPath"] = "/spear/document/ViewContent.do"
        args_dict["documentUrlQuery"] = "documentId=104353&documentViewType=AS_PER_DOCTYPE&spearAppToken=7605&dmdInternalID=107786&caller=details,viewVersionsPage107786"
        request_rs.arguments_dict = args_dict
        output_rs = a2pspear_service.do_process_request(request_rs, spaces)
        self.assertEqual(True, output_rs.success)
        self.assertTrue(output_rs.sid006a_dict)
        # checking some fields that should always be there
        self.assertTrue('sid006a_supplied_by' in output_rs.sid006a_dict)
        self.assertTrue('sid006a_application_type' in output_rs.sid006a_dict)
        self.assertTrue('sid006a_spear_reference_number' in output_rs.sid006a_dict)
        self.assertTrue('sid006a_submitted_date' in output_rs.sid006a_dict)
        self.assertTrue('sid006a_supplied_by' in output_rs.sid006a_dict)
        self.assertTrue('sid006a_version_number' in output_rs.sid006a_dict)         

    def test_do_process_request_application_document_pdf(self):
        NodeLogger.logger_names['eplanning.spear.a2pspear_service'] = logging.DEBUG
        NodeLogger.logger_names['eplanning.spear.a2pspear_service.A2PSpearService'] = logging.DEBUG
        NodeLogger.setStreamHandler()        
        NodeLogger.load()
        spaces = Spaces()
        service_uri = Uri('dummy')
        ds = None
        config_rs = self.get_a2pspear_service_configuration()
        A2PSpearService.get_requests_resources_from_datastore = self.get_requests_resources_from_datastore
        A2PSpearService.get_instruction_resource_from_datastore = self.get_instruction_resource_from_datastore
        a2pspear_service = A2PSpearService(spaces, ds, service_uri)
        a2pspear_service.statics = config_rs.services["eplanning/spear/a2pspear_service"].options.statics
        request_rs = spaces.get(Uri("spear:request/login"))
        output_rs = a2pspear_service.do_process_request(request_rs, spaces)
        self.assertEqual(True, output_rs.success)
        request_rs = spaces.get(Uri("spear:request/applicationdocument-pdf"))
        args_dict = {}
        args_dict["user_role_council"] = "85:RESPONSIBLE_AUTHORITY"
        args_dict["documentUrlPath"] = "/spear/document/ViewContent.do"
        args_dict["documentUrlQuery"] = "documentId=104354&documentViewType=AS_PER_DOCTYPE&spearAppToken=7605&dmdInternalID=107787&caller=details,viewVersionsPage107787"
        request_rs.arguments_dict = args_dict
        output_rs = a2pspear_service.do_process_request(request_rs, spaces)
        self.assertEqual(True, output_rs.success)
        self.assertNotEqual(None, output_rs.pdf)
        
    def test_do_process_request_application_document_responsibleauthorityreferencenumber(self):
        NodeLogger.logger_names['eplanning.spear.a2pspear_service'] = logging.DEBUG
        NodeLogger.logger_names['eplanning.spear.a2pspear_service.A2PSpearService'] = logging.DEBUG
        NodeLogger.setStreamHandler()        
        NodeLogger.load()
        spaces = Spaces()
        service_uri = Uri('dummy')
        ds = None
        config_rs = self.get_a2pspear_service_configuration()
        A2PSpearService.get_requests_resources_from_datastore = self.get_requests_resources_from_datastore
        A2PSpearService.get_instruction_resource_from_datastore = self.get_instruction_resource_from_datastore
        a2pspear_service = A2PSpearService(spaces, ds, service_uri)
        a2pspear_service.statics = config_rs.services["eplanning/spear/a2pspear_service"].options.statics
        request_rs = spaces.get(Uri("spear:request/login"))
        output_rs = a2pspear_service.do_process_request(request_rs, spaces)
        self.assertEqual(True, output_rs.success)
        request_rs = spaces.get(Uri("spear:request/applicationdetails"))
        args_dict = {}
        args_dict["spearReferenceNumber"] = 'S007533P'
        args_dict["user_role_council"] = "85:RESPONSIBLE_AUTHORITY"
        request_rs.arguments_dict = args_dict
        output_rs = a2pspear_service.do_process_request(request_rs, spaces)
        self.assertEqual(True, output_rs.success)
        request_rs = spaces.get(Uri("spear:request/applicationdocument-responsibleauthorityreferencenumber"))
        args_dict = {}
        args_dict["user_role_council"] = "85:RESPONSIBLE_AUTHORITY"
        args_dict["documentUrlPath"] = "/spear/document/View.do"
        args_dict["documentUrlQuery"] = "documentId=108006&spearAppToken=7605&dmdInternalID=111580&caller=details"
        request_rs.arguments_dict = args_dict
        output_rs = a2pspear_service.do_process_request(request_rs, spaces)
        self.assertEqual(True, output_rs.success)
        self.assertTrue('sid072a_reference_number_1' in output_rs.sid072a_dict)
        self.assertTrue('sid072a_plan_number' in output_rs.sid072a_dict)
        self.assertTrue('sid072a_delegate_planning_officer_full_name' in output_rs.sid072a_dict)
        self.assertTrue('sid072a_spear_ref' in output_rs.sid072a_dict)
        
    def test_do_process_request_application_document_referralrequest(self):
        NodeLogger.logger_names['eplanning.spear.a2pspear_service'] = logging.DEBUG
        NodeLogger.logger_names['eplanning.spear.a2pspear_service.A2PSpearService'] = logging.DEBUG
        NodeLogger.setStreamHandler()        
        NodeLogger.load()
        spaces = Spaces()
        service_uri = Uri('dummy')
        ds = None
        config_rs = self.get_a2pspear_service_configuration()
        A2PSpearService.get_requests_resources_from_datastore = self.get_requests_resources_from_datastore
        A2PSpearService.get_instruction_resource_from_datastore = self.get_instruction_resource_from_datastore
        a2pspear_service = A2PSpearService(spaces, ds, service_uri)
        a2pspear_service.statics = config_rs.services["eplanning/spear/a2pspear_service"].options.statics
        request_rs = spaces.get(Uri("spear:request/login"))
        output_rs = a2pspear_service.do_process_request(request_rs, spaces)
        self.assertEqual(True, output_rs.success)
        request_rs = spaces.get(Uri("spear:request/applicationdetails"))
        args_dict = {}
        args_dict["spearReferenceNumber"] = 'S007533P'
        args_dict["user_role_council"] = "85:RESPONSIBLE_AUTHORITY"
        request_rs.arguments_dict = args_dict
        output_rs = a2pspear_service.do_process_request(request_rs, spaces)
        self.assertEqual(True, output_rs.success)        
        request_rs = spaces.get(Uri("spear:request/applicationdocument-referralrequest"))
        args_dict = {}
        args_dict["user_role_council"] = "85:RESPONSIBLE_AUTHORITY"
        args_dict["documentUrlPath"] = "/spear/document/View.do"
        args_dict["documentUrlQuery"] = "documentId=107014&spearAppToken=7605&dmdInternalID=110557&caller=details"
        request_rs.arguments_dict = args_dict
        output_rs = a2pspear_service.do_process_request(request_rs, spaces)
        self.assertEqual(True, output_rs.success)
        self.assertTrue('sid061a_ra_dict_dict' in output_rs.sid061a_dict)
        # should always be at least 1 RA
        self.assertTrue(len(output_rs.sid061a_dict['sid061a_ra_dict_dict'].keys()) > 0)
        ra_0_key = output_rs.sid061a_dict['sid061a_ra_dict_dict'].keys()[0]
        self.assertTrue('sid061a_council_ra_comments' in output_rs.sid061a_dict['sid061a_ra_dict_dict'][ra_0_key])
        self.assertTrue('sid061a_ra_requirements' in output_rs.sid061a_dict['sid061a_ra_dict_dict'][ra_0_key])
        self.assertTrue('sid061a_ra_name' in output_rs.sid061a_dict['sid061a_ra_dict_dict'][ra_0_key])
        
    def test_do_process_request_application_document_racomments(self):
        NodeLogger.logger_names['eplanning.spear.a2pspear_service'] = logging.DEBUG
        NodeLogger.logger_names['eplanning.spear.a2pspear_service.A2PSpearService'] = logging.DEBUG
        NodeLogger.setStreamHandler()        
        NodeLogger.load()
        spaces = Spaces()
        service_uri = Uri('dummy')
        ds = None
        config_rs = self.get_a2pspear_service_configuration()
        A2PSpearService.get_requests_resources_from_datastore = self.get_requests_resources_from_datastore
        A2PSpearService.get_instruction_resource_from_datastore = self.get_instruction_resource_from_datastore
        a2pspear_service = A2PSpearService(spaces, ds, service_uri)
        a2pspear_service.statics = config_rs.services["eplanning/spear/a2pspear_service"].options.statics
        request_rs = spaces.get(Uri("spear:request/login"))
        output_rs = a2pspear_service.do_process_request(request_rs, spaces)
        self.assertEqual(True, output_rs.success)
        request_rs = spaces.get(Uri("spear:request/applicationdocument-racomments"))
        args_dict = {}
        args_dict["user_role_council"] = "85:RESPONSIBLE_AUTHORITY"
        args_dict["documentUrlPath"] = "/spear/referralResponse/ViewComments.do"
        args_dict["documentUrlQuery"] = "documentId=104407&spearAppToken=7605&dmdInternalID=107848&caller=details"
        request_rs.arguments_dict = args_dict
        output_rs = a2pspear_service.do_process_request(request_rs, spaces)
        self.assertEqual(True, output_rs.success)
        self.assertTrue('sid075c_comments' in output_rs.sid075c_dict)
        self.assertTrue('sid075c_date' in output_rs.sid075c_dict)
        self.assertTrue('sid075c_org_name' in output_rs.sid075c_dict)
        
    def test_do_process_request_activity_log(self):
        NodeLogger.logger_names['eplanning.spear.a2pspear_service'] = logging.DEBUG
        NodeLogger.logger_names['eplanning.spear.a2pspear_service.A2PSpearService'] = logging.DEBUG
        NodeLogger.setStreamHandler()        
        NodeLogger.load()
        spaces = Spaces()
        service_uri = Uri('dummy')
        ds = None
        config_rs = self.get_a2pspear_service_configuration()
        A2PSpearService.get_requests_resources_from_datastore = self.get_requests_resources_from_datastore
        A2PSpearService.get_instruction_resource_from_datastore = self.get_instruction_resource_from_datastore
        a2pspear_service = A2PSpearService(spaces, ds, service_uri)
        a2pspear_service.statics = config_rs.services["eplanning/spear/a2pspear_service"].options.statics
        request_rs = spaces.get(Uri("spear:request/login"))
        output_rs = a2pspear_service.do_process_request(request_rs, spaces)
        self.assertEqual(True, output_rs.success)
        request_rs = spaces.get(Uri("spear:request/activitylog"))
        args_dict = {}
        args_dict["startDate"] = datetime.datetime.now().strftime("%Y%m%dT%H%M%S")
        args_dict["user_role_council"] = "85:RESPONSIBLE_AUTHORITY"
        request_rs.arguments_dict = args_dict
        output_rs = a2pspear_service.do_process_request(request_rs, spaces)
        self.assertEqual(True, output_rs.success)
        self.assertTrue(output_rs.has_var('xml'))


if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    unittest.main()